// 发送邮件 给id=emailBtn 元素添加点击事件  click() 点击事件
$("#emailBtn").click(function(){
    //获取邮箱账号
    var email=$("#email").val();
    $.getJSON("/sendEmail",{"email":email},function(data){
        if(data.state==200){
            layer.msg(data.message);
        }else{
            layer.msg(data.message);
        }
    });
});

//注册按钮onclick事件改为register()即可
function register() {
    var loginName = $("#loginName").val();
    if (!validPhoneNumber(loginName)) {
        swal('请输入正确的登录名(即手机号)', {
            icon: "error",
        });
        return false;
    }
    var password = $("#password").val();
    if (!validPassword(password)) {
        swal('请输入正确的密码格式(6-20位字符和数字组合)', {
            icon: "error",
        });
        return false;
    }
    var email = $("#email").val();
    if (!validEmail(email)) {
        swal('请输入正确的邮箱', {
            icon: "error",
        });
        return false;
    }
    var verifyCode = $("#verifyCode").val();
    if (!validLength(verifyCode, 6)) {
        swal('请输入正确的验证码', {
            icon: "error",
        });
        return false;
    }
    //验证
    var params = $("#registerForm").serialize();
    var url = '/doRegister';
    $.ajax({
        type: 'POST',//方法类型
        url: url,
        data: params,
        success: function (result) {
            if (result.resultCode == 200) {
                swal({
                    title: "注册成功",
                    text: "是否跳转至登录页?",
                    icon: "success",
                    buttons: true,
                    dangerMode: true,
                }).then((flag) => {
                        if (flag) {
                            window.location.href = '/login';
                        }
                    }
                )
                ;
            } else {
                swal(result.message, {
                    icon: "error",
                });
            }
            ;
        },
        error: function () {
            swal("注册失败", {
                icon: "error",
            });
        }
    });
}